package org.abadirou.cdebacker.flst.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.abadirou.cdebacker.flst.api.Chambre;
import org.abadirou.cdebacker.flst.api.OptionChambre;

@Entity(name = "OptionChambre")
@NamedQueries({
	@NamedQuery(name = "ALL_OPTION", query = "FROM OptionChambre ORDER BY name DESC"),
	@NamedQuery(name = "OPTION_BY_NAME", query = "FROM OptionChambre WHERE name = :name")
})
public class OptionChambreImpl implements OptionChambre{

	public static final String ALL_OPTION = "ALL_OPTION";
	public static final String OPTION_BY_NAME = "OPTION_BY_NAME";

	@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
	private Long id;
	
	private String name;
	
	@ManyToMany(mappedBy="optionByChambres")
	private List<ChambreImpl> chambres = new ArrayList<ChambreImpl>();
	
	public OptionChambreImpl(){
		
	}
	
	public OptionChambreImpl(String name) {
		this.name = name;
	}


	@Override
	public String getName() {
		return name;
	}

	@Override
	public List<? extends Chambre> getChambresByOption() {
		return chambres;
	}

	@Override
	public int hashCode() {
		return getName().hashCode();
	}

	@Override
	public boolean equals(Object obj) {

	if (!(obj instanceof OptionChambre)){
		return false;
	}
	return ((OptionChambre) obj).getName().equals(getName());
	
	}

	public Long getId() {
		return id;
	}

}
